package io.github.codelifeleno.jdbrelease.execute.StringStream;

public class RuleCombinators {
    // 组合多个正向规则（逻辑 AND）
    public static PositiveRule and(PositiveRule... rules) {
        return (buffer, c) -> {
            for (PositiveRule rule : rules) {
                if (!rule.test(buffer, c)) return false;
            }
            return true;
        };
    }

    // 组合多个正向规则（逻辑 or）
    public static PositiveRule or(PositiveRule... rules) {
        return (buffer, c) -> {
            for (PositiveRule rule : rules) {
                if (rule.test(buffer, c)) return true;
            }
            return false;
        };
    }

    // 组合多个逆向规则（逻辑 OR）
    public static NegativeRule or(NegativeRule... rules) {
        return (buffer, c) -> {
            for (NegativeRule rule : rules) {
                if (rule.test(buffer, c)) return true;
            }
            return false;
        };
    }

    // 组合多个逆向规则（逻辑 and）
    public static NegativeRule and(NegativeRule... rules) {
        return (buffer, c) -> {
            for (NegativeRule rule : rules) {
                if (!rule.test(buffer, c)) return false;
            }
            return true;
        };
    }
}